#include "config.h"
#include "platform.h"

#include <QCoreApplication>
#include <QTextStream>

//////////////////////////////////////////////////////////////////////////

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    (void)app;

    QString script_file("neonmake.js");
    QString script_plat("win");
    QString script_cc  ("vc11");

    for (int i = 0; i < argc; ++i)
    {
        if (strcmp(argv[i], "-f") == 0)
        {
            if (++i >= argc) break;
            script_file = argv[i];
        }
        else if (strcmp(argv[i], "-p") == 0)
        {
            if (++i >= argc) break;
            script_plat = argv[i];
        }
        else if (strcmp(argv[i], "-c") == 0)
        {
            if (++i >= argc) break;
            script_cc = argv[i];
        }
    }

    forever
    {
        QTextStream(stdout) << "\n"
            << "Script File: " << script_file << "\n"
            << "Target Plat: " << script_plat << "\n"
            << "Target CC:   " << script_cc << "\n\n"
            << "OK to start it ? (y/n/f/p/c) ";

        QString in;
        QTextStream(stdin) >> in;

        if (in == "y") break;

        QTextStream(stdout) << "\nPlease enter a new setting: ";
        if (in == "f")
        {
            QTextStream(stdout) << "(ini/js/...)\n";
            QTextStream(stdin) >> script_file;
        }
        else if (in == "p")
        {
            QTextStream(stdout) << "(linux/win/...)\n";
            QTextStream(stdin) >> script_plat;
        }
        else if (in == "c")
        {
            QTextStream(stdout) << "(gcc/vc8/vc9/...)\n";
            QTextStream(stdin) >> script_cc;
        }
        else
        {
            QTextStream(stdout) << "(filename linux gcc)\n";
            QTextStream(stdin) >> script_file >> script_plat >> script_cc;
        }
    }

    Config config(script_file, script_plat, script_cc);
    if (Platform(config).make())
    {
        QTextStream(stdout) << "\n"
            << "Make Successes!" << "\n";
    }
    else
    {
        QTextStream(stdout) << "\n"
            << "Make Failure!" << " ->: "
            << config.get_message() << "\n";
        system("pause");
    }

    return 0/*app.exec()*/;
}
